package com.uniqueyi.baselib.atybase.mvp;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.net.URLEncoder;

import io.xujiaji.xmvp.presenters.XBasePresenter;
import io.xujiaji.xmvp.utils.GenericHelper;

/**
 * Created by
 * author:  cwy.
 * date:    2017/12/25.  11:27.
 * prj:     crxls.
 */

public abstract class BaseAty<T extends XBasePresenter, VD extends ViewDataBinding> extends AppCompatActivity implements View.OnClickListener {

    protected Context context;

    protected T presenter;

    // 布局view
    protected VD bindingView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        beforeSetContentView();
//        setContentView(setLayIds());
        bindingView = DataBindingUtil.setContentView(this, setLayIds());
        context = this;
        try {
            presenter = GenericHelper.newPresenter(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (presenter != null) {
            presenter.start();
        }
        onInit();
        onListener();
    }

    @Override
    public void setContentView(@LayoutRes int layoutResID) {
        super.setContentView(layoutResID);

//        bindingView = DataBindingUtil.inflate(getLayoutInflater(), layoutResID, null, false);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) {
            presenter.end();
        }
    }

    /**
     * 需要在SetContentView之前做的操作
     */
    protected void beforeSetContentView() {
    }

    /**
     * 在这里面进行初始化
     */
    protected void onInit() {
    }

    /**
     * 这里面写监听事件
     */
    protected void onListener() {
    }

    public abstract int setLayIds();
}